﻿using System;
using Abp.Authorization.Users;
using Abp.Extensions;
using Microsoft.AspNet.Identity;
using System.ComponentModel.DataAnnotations;

namespace FutureApp.Users
{
    /// <summary>
    /// 用户
    /// </summary>
    public class User : AbpUser<User>
    {  
        /// <summary>
        ///身份证号
        /// </summary>
        [StringLength(15)]
        public virtual string IdentityCard { get; set; }
        /// <summary>
        ///手机号
        /// </summary>
        [StringLength(11)]
        public virtual string Telephone { get; set; }
        /// <summary>
        ///商家名称
        /// </summary>
        [StringLength(30)]
        public virtual string ShopName { get; set; }
        /// <summary>
        ///商家账号
        /// </summary>
        [StringLength(30)]
        public virtual string ShopId { get; set; }
        /// <summary>
        ///账号密码
        /// </summary>
        [StringLength(50)]
        public virtual string ShopPassword { get; set; }
        /// <summary>
        ///经营品类
        /// </summary>
        [StringLength(30)]
        public virtual string ShopItem{ get; set; }
        /// <summary>
        ///商家账户
        /// </summary>
        [StringLength(60)]
        public virtual string ShopCard { get; set; }
        /// <summary>
        ///地址
        /// </summary>
        [StringLength(60)]
        public virtual string Address { get; set; }
        /// <summary>
        ///用户类型：1商家，2个人用户
        /// </summary>
       
        public virtual int? UserType{ get; set; }
        /// <summary>
        /// 用户默认密码
        /// </summary>
        public const string DefaultAdminPassword = "123qwe";

        /// <summary>
        /// 用户默认密码
        /// </summary>
        public const string DefaultPassword = "123456";

        /// <summary>
        /// 创建随机密码
        /// </summary>
        public static string CreateRandomPassword()
        {
            return Guid.NewGuid().ToString("N").Truncate(16);
        }

        /// <summary>
        /// 创建租户下的管理员
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <param name="emailAddress">邮箱地址</param>
        /// <param name="password">密码</param>
        /// <returns>返回代表管理员的用户</returns>
        public static User CreateTenantAdminUser(int tenantId, string emailAddress, string password)
        {
            return new User
            {
                TenantId = tenantId,
                UserName = AdminUserName,
                Name = AdminUserName,
                Surname = AdminUserName,
                EmailAddress = emailAddress,
                Password = new PasswordHasher().HashPassword(password)
            };
        }
    }
}